function WorkerVideographer() {
};

WorkerVideographer.instance = function(callbackFunc) {
  var popupBox = new PopupBox(), _self = this;
  var popupBox2 = new PopupBox2();
  var model = Model.instance('{{$smarty.const.MODEL_NAME_USER_VIDEOGRAPHER|escape:javascript}}', '{{$smarty.const.MODEL_TITLE_USER_VIDEOGRAPHER|escape:javascript}}', '{{$smarty.const.MODEL_TYPE_PRODUCT|escape:javascript}}');
  
  
  //Create model here...
  var state1 = State.instance(model, 0, 'not activate (No Wedding Day)');
  var state2 = State.instance(model, 1, 'arrange  videographer');
  var state3 = State.instance(model, 2, 'confirm videographer');
  var state4 = State.instance(model, 3, 'remind videographer');
  var state5 = State.instance(model, 4, 'receive video tape');
  var state6 = State.instance(model, 5, 'backup video tape');
  var state7 = State.instance(model, 6, 'post video tape');
  var state8 = State.instance(model, 7, 'receive video tape');
  var state9 = State.instance(model, 8, 'capture video tape');
  var state10 = State.instance(model, 9, 'video tape ready');
  
  var transition1 = Transition.instance('select', state2, state3, '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}', DlmanageUtils.dop, -30);
  var transition2 = Transition.instance('confirmed', state3, state4, '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}', DlmanageUtils.dop, -2);
  var transition3 = Transition.instance('reminded', state4, state5, '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}', DlmanageUtils.dop, 4);
  var transition4 = Transition.instance('received', state5, state6, '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}', DlmanageUtils.normal, 2);
  var transition5 = Transition.instance('completed', state6, state7, '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition6 = Transition.instance('sent', state7, state8, 'Waiting for post', DlmanageUtils.normal, 7);  
  var transition7 = Transition.instance('received', state8, state9, '{{$smarty.const.USER_TYPE_FILM_CUTTER|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition8 = Transition.instance('completed', state6, state7, '{{$smarty.const.USER_TYPE_CUSTOMER_SERVICE|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition9 = Transition.instance('completed', state9, state10, '{{$smarty.const.USER_TYPE_FILM_CUTTER|escape:javascript}}', DlmanageUtils.none);

  var transition10 = Transition.instance('select', state2, state3, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.dop, -30);
  var transition11 = Transition.instance('confirmed', state3, state4, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.dop, -2);
  var transition12 = Transition.instance('reminded', state4, state5, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.dop, 4);
  var transition13 = Transition.instance('received', state5, state6, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.normal, 2);
  var transition14 = Transition.instance('completed', state6, state7, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition15 = Transition.instance('sent', state7, state8, 'Waiting for post', DlmanageUtils.normal, 7);
  var transition16 = Transition.instance('received', state8, state9, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition17 = Transition.instance('completed', state9, state10, '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}', DlmanageUtils.none);

  var transition18 = Transition.instance('select', state2, state3, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.dop, -30);
  var transition19 = Transition.instance('confirmed', state3, state4, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.dop, -2);
  var transition20 = Transition.instance('reminded', state4, state5, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.dop, 4);
  var transition21 = Transition.instance('received', state5, state6, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.normal, 2);
  var transition22 = Transition.instance('completed', state6, state7, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition23 = Transition.instance('sent', state7, state8, 'Waiting for post', DlmanageUtils.normal, 7);
  var transition24 = Transition.instance('received', state8, state9, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.normal, 3);
  var transition25 = Transition.instance('completed', state9, state10, '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}', DlmanageUtils.none);

  transition4.validate = function(produce, user, date, options) { if (transition4.position != user.type) { return false; } if (SimpleDate.toStamp(date) < SimpleDate.toStamp(produce.date)) { return false; } else { return true; } };
  transition7.validate = function(produce, user, date, options) { return false; };

  transition13.validate = function(produce, user, date, options) { if (transition13.position != user.type) { return false; } if (SimpleDate.toStamp(date) < SimpleDate.toStamp(produce.date)) { return false; } else { return true; } };
  transition16.validate = function(produce, user, date, options) { return false; };
  

  transition21.validate = function(produce, user, date, options) { if (transition21.position != user.type) { return false; } if (SimpleDate.toStamp(date) < SimpleDate.toStamp(produce.date)) { return false; } else { return true; } };
  transition24.validate = function(produce, user, date, options) { return false; };
  
  transition1.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    var div = document.createElement('div');
                                                                                    var func1 = function() { if (!options) {
                                                                                                               options = {};
                                                                                                             }
                                                                                                             if (produce.user_account == '') {
                                                                                                               window.alert('选择一个工作人员');
                                                                                                               return;
                                                                                                             }
                                                                                                             options.extra = produce.user_account;
                                                                                                             var func3 = function(){
                                                                                                                DlmanageUtils.operate(transition1, pos, callbackFunc, produce, user, date, options);
                                                                                                             }
                                                                                                             
                                                                                                              DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                                             popupBox._close();
                                                                                                           };
                                                                                    var func2 = function() { popupBox._close();
                                                                                                             callbackFunc();
                                                                                                           };
                                                                                    MiscUtils.dialog(popupBox, pos, div, func1, func2);
                                                                                    new DialogAssignee(div, produce, { php: 'customphp/mysqlread.php', condition: 'd.vEnabled = 1', orderTrackId: produce.orderTrackId });
                                                                                  };
  
   transition2.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  options.func = function(div, pos, options) { MiscUtils.dialog(popupBox, pos, div); };
                                                                                  
                                                                                  
                                                                                                           options.extra = produce.user_account;
                                                                                                           
                                                                                                               var func3 = function(){
                                                                                                                DlmanageUtils.operate(transition2, pos, callbackFunc, produce, user, date, options);
                                                                                                             }
                                                                                                             
                                                                                                              DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                
                                                                                }; 
 
  transition3.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    options.stage = 2;
                                                                                    options.func = function(div, customer, options) { new DialogLocation(div, customer, options); };
                                                                                    
                                                                                    var func3 = function(){
                                                                                     DlmanageUtils.operate3(transition3, pos, callbackFunc, produce, user, date, options);
                                                                                    }
                                                                                    
                                                                                     DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                  };
                                                                                  
  transition4.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    var div = document.createElement('div');
                                                                                    var func1 = function() { if (produce._text == '') {
                                                                                                               window.alert('CAN NOT BE EMPTY');
                                                                                                               return;
                                                                                                             }
                                                                                                             if (!options) {
                                                                                                               options = {};
                                                                                                             }
                                                                                                             options.extra = produce._text;
                                                                                                             DlmanageUtils.operate(transition4, pos, callbackFunc, produce, user, date, options);
                                                                                                             popupBox2._close();
                                                                                                           };
                                                                                    var func2 = function() { popupBox2._close();
                                                                                                             callbackFunc();
                                                                                                           };
                                                                                    MiscUtils.dialog(popupBox2, pos, div, func1, func2, {t: '请写下Video Tape的数量', func: function() { callbackFunc(); } });
                                                                                    var dmodel = 'Mini tapes quantity: ' + '\n' 
                                                                                                  +'DVD quantity:' + '\n'
                                                                                                 +'Hard disks quantity：';
                                                                                    
                                                                                    new DialogInput(div, produce, { title: '' ,default:dmodel });
                                                                                  };
                                                                                  
  transition9.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    options.branch = previous.branch;
                                                                                    options.host = previous.host;
                                                                                    options.orderDate = produce.date;
                                                                                    options.user = user;
                                                                                    options.date = date;
                                                                                    options.orderFlag = produce.orderFlag;
                                                                                    options.orderTrackId = produce.orderTrackId;
                                                                                    options.orderId = produce.orderId;
                                                                                    options.customerId = produce.customerId;
                                                                                    DlmanageUtils.operate2(transition9, pos, callbackFunc, produce, user, date, options);
                                                                                  };
                                                                                  
                                                                                  
                                                                                  
  transition10.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    var div = document.createElement('div');
                                                                                    var func1 = function() { if (!options) {
                                                                                                               options = {};
                                                                                                             }
                                                                                                             if (produce.user_account == '') {
                                                                                                               window.alert('选择一个工作人员');
                                                                                                               return;
                                                                                                             }
                                                                                                             options.extra = produce.user_account;
                                                                                                             var func3 = function(){
                                                                                                                DlmanageUtils.operate(transition10, pos, callbackFunc, produce, user, date, options);
                                                                                                             }
                                                                                                             
                                                                                                              DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                                             popupBox._close();
                                                                                                           };
                                                                                    var func2 = function() { popupBox._close();
                                                                                                             callbackFunc();
                                                                                                           };
                                                                                    MiscUtils.dialog(popupBox, pos, div, func1, func2);
                                                                                    new DialogAssignee(div, produce, { php: 'customphp/mysqlread.php', condition: 'd.vEnabled = 1', orderTrackId: produce.orderTrackId });
                                                                                  };

  transition11.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  options.func = function(div, pos, options) { MiscUtils.dialog(popupBox, pos, div); };
                                                                                  
                                                                                  
                                                                                                           options.extra = produce.user_account;
                                                                                                           
                                                                                                               var func3 = function(){
                                                                                                                DlmanageUtils.operate(transition11, pos, callbackFunc, produce, user, date, options);
                                                                                                             }
                                                                                                             
                                                                                                              DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                
                                                                                }; 


  transition12.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    options.stage = 2;
                                                                                    options.func = function(div, customer, options) { new DialogLocation(div, customer, options); };
                                                                                     
                                                                                    var func3 = function(){ 
                                                                                     DlmanageUtils.operate3(transition12, pos, callbackFunc, produce, user, date, options);
                                                                                    }
                                                                                     DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                  };
                                                                                
  transition13.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    var div = document.createElement('div');
                                                                                    var func1 = function() { if (produce._text == '') {
                                                                                                               window.alert('CAN NOT BE EMPTY');
                                                                                                               return;
                                                                                                             }
                                                                                                             if (!options) {
                                                                                                               options = {};
                                                                                                             }
                                                                                                             options.extra = produce._text;
                                                                                                             DlmanageUtils.operate(transition13, pos, callbackFunc, produce, user, date, options);
                                                                                                             popupBox2._close();
                                                                                                           };
                                                                                    var func2 = function() { popupBox2._close();
                                                                                                             callbackFunc();
                                                                                                           };
                                                                                                           
                                                                                    var dmodel = 'Mini tapes quantity: ' + '\n' 
                                                                                                  +'DVD quantity:' + '\n'
                                                                                                 +'Hard disks quantity：';                                                                                                               
                                                                                                           
                                                                                    MiscUtils.dialog(popupBox2, pos, div, func1, func2, {t: '请写下Video Tape的数量', func: function() { callbackFunc(); } });
                                                                                    new DialogInput(div, produce, { title: '',default:dmodel });
                                                                                  };
                                                                                
  transition17.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                      options = {};
                                                                                    }
                                                                                    var previous = MiscUtils.clone(produce);
                                                                                    options.previous = previous;
                                                                                    options.branch = previous.branch;
                                                                                    options.host = previous.host;
                                                                                    options.orderDate = produce.date;
                                                                                    options.user = user;
                                                                                    options.date = date;
                                                                                    options.orderFlag = produce.orderFlag;
                                                                                    options.orderTrackId = produce.orderTrackId;
                                                                                    options.orderId = produce.orderId;
                                                                                    options.customerId = produce.customerId;
                                                                                    DlmanageUtils.operate2(transition17, pos, callbackFunc, produce, user, date, options);
                                                                                  };
transition18.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  var div = document.createElement('div');
                                                                                  var func1 = function() { if (!options) {
                                                                                                             options = {};
                                                                                                           }
                                                                                                           if (produce.user_account == '') {
                                                                                                             window.alert('选择一个工作人员');
                                                                                                             return;
                                                                                                           }
                                                                                                           options.extra = produce.user_account;
                                                                                                             var func3 = function(){
                                                                                                                DlmanageUtils.operate(transition18, pos, callbackFunc, produce, user, date, options);
                                                                                                             }
                                                                                                             
                                                                                                              DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                                           popupBox._close();
                                                                                                         };
                                                                                  var func2 = function() { popupBox._close();
                                                                                                           callbackFunc();
                                                                                                         };
                                                                                  MiscUtils.dialog(popupBox, pos, div, func1, func2);
                                                                                  new DialogAssignee(div, produce, { php: 'customphp/mysqlread.php', condition: 'd.vEnabled = 1', orderTrackId: produce.orderTrackId });
                                                                                };

  transition19.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  options.func = function(div, pos, options) { MiscUtils.dialog(popupBox, pos, div); };
                                                                                  
                                                                                  
                                                                                                           options.extra = produce.user_account;
                                                                                                           
                                                                                                               var func3 = function(){
                                                                                                                DlmanageUtils.operate(transition19, pos, callbackFunc, produce, user, date, options);
                                                                                                             }
                                                                                                             
                                                                                                              DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                
                                                                                }; 

transition20.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  options.stage = 2;
                                                                                  options.func = function(div, customer, options) { new DialogLocation(div, customer, options); };
                                                                                  
                                                                                  var func3 = function(){
                                                                                   DlmanageUtils.operate3(transition20, pos, callbackFunc, produce, user, date, options);
                                                                                  }
                                                                                   DlmanageUtils.sendEmail(produce,pos,func3,callbackFunc);
                                                                                };
                                                                              
transition21.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  var div = document.createElement('div');
                                                                                  var func1 = function() { if (produce._text == '') {
                                                                                                             window.alert('CAN NOT BE EMPTY');
                                                                                                             return;
                                                                                                           }
                                                                                                           if (!options) {
                                                                                                             options = {};
                                                                                                           }
                                                                                                           options.extra = produce._text;
                                                                                                           DlmanageUtils.operate(transition21, pos, callbackFunc, produce, user, date, options);
                                                                                                           popupBox2._close();
                                                                                                         };
                                                                                  var func2 = function() { popupBox2._close();
                                                                                                           callbackFunc();
                                                                                                         };
                                                                                    var dmodel = 'Mini tapes quantity: ' + '\n' 
                                                                                                  +'DVD quantity:' + '\n'
                                                                                                 +'Hard disks quantity：';                                                                                                         
                                                                                                         
                                                                                  MiscUtils.dialog(popupBox2, pos, div, func1, func2, {t: '请写下Video Tape的数量', func: function() { callbackFunc(); } });
                                                                                  new DialogInput(div, produce, { title: '',default:dmodel });
                                                                                };
                                                                              
transition25.operate = function(pos, callbackFunc, produce, user, date, options) { if (!options) {
                                                                                    options = {};
                                                                                  }
                                                                                  var previous = MiscUtils.clone(produce);
                                                                                  options.previous = previous;
                                                                                  options.branch = previous.branch;
                                                                                  options.host = previous.host;
                                                                                  options.orderDate = produce.date;
                                                                                  options.user = user;
                                                                                  options.date = date;
                                                                                  options.orderFlag = produce.orderFlag;
                                                                                  options.orderTrackId = produce.orderTrackId;
                                                                                  options.orderId = produce.orderId;
                                                                                  options.customerId = produce.customerId;
                                                                                  DlmanageUtils.operate2(transition25, pos, callbackFunc, produce, user, date, options);
                                                                                };
  model.states = [ state1, state2, state3, state4, state5, state6, state7, state8, state9, state10 ];
  model.transitions = [ transition1, transition2, transition3, transition4, transition5, transition6, transition7, transition8, transition9, transition10, transition11, transition12, transition13, transition14, transition15, transition16, transition17, transition18, transition19, transition20,
                        transition21, transition22, transition23, transition24, transition25 ];
  return model;
};